package com.bestcem.xm.award.controller.param.requestaward;

import com.alibaba.fastjson.JSON;
import com.bestcem.xm.award.entity.pojo.AwardRequestDO;
import com.bestcem.xm.award.enums.DeviceTypeEnum;
import com.bestcem.xm.award.grpc.service.param.requestaward.GetRequestAwardParam;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Map;

/**
 * 答题端完成答卷获取奖励 请求参数
 *
 * @author jie.yao <jie.yao@idiaoyan.com>
 * @version v1.0
 * @date 2021/8/19 14:18
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class GetRequestAwardQuery {

    /**
     * 投放信息
     */
    @JsonProperty("deliver")
    private Map<String, Object> deliver;

    /**
     * 答卷信息
     */
    @JsonProperty("respondent")
    private Map<String, Object> respondent;

    /**
     * 设备信息 {@link DeviceTypeEnum}
     */
    @JsonProperty("device_type")
    private Integer deviceType;

    /**
     * 设备访问次数
     */
    @JsonProperty("visited_count")
    private Integer visitedCount;

    /**
     * 入参转换为service层所需参数
     *
     * @param remoteIp 请求端ip
     * @return GetRequestAwardParam
     */
    public GetRequestAwardParam getRequestAwardParam(String remoteIp) {
        GetRequestAwardParam param = new GetRequestAwardParam();
        param.setIp(remoteIp);
        param.setDeviceType(this.deviceType);
        param.setVisitedCount(this.visitedCount);
        param.setDeliverMap(this.deliver);
        param.setDeliver(JSON.parseObject(JSON.toJSONString(deliver), AwardRequestDO.Deliver.class));
        param.setSurvey(JSON.parseObject(JSON.toJSONString(respondent), AwardRequestDO.Survey.class));
        return param;
    }
}
